package com.ditri.distrident.common.configuration;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import javax.sound.midi.Patch;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author: edxuanlen
 * @Date: 2020/8/1:16:49
 */


@ConditionalOnProperty(prefix = "swagger", name = "open", havingValue = "true")
@Configuration
@EnableSwagger2
@RefreshScope
@EnableAutoConfiguration
public class SwaggerConfiguration {


    @Bean
    public Docket createRestApi() {

        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(defaultTitleInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.ditri.distrident.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * 默认标题信息
     *
     * @return
     */
    private ApiInfo defaultTitleInfo() {
        // 大标题
        return new ApiInfoBuilder().title("distrident API")
                // 详细描述
                .description("distrident 后台API")
                .contact(ApiInfo.DEFAULT_CONTACT)
                // 版本
                .version("1.0")
                .build();
    }

}